//
//  BidInvestRecordSectionHeaderView.swift
//  cxd4iphone
//
//  Created by hexy on 12/23/15.
//  Copyright © 2015 hexy. All rights reserved.
//

import UIKit

private struct kConstraints {
    
    static let wrapEdges: UIEdgeInsets = UIEdgeInsetsMake(10, 10, -10, -10)
    static let margin: CGFloat         = 10
    static let topViewHeight: CGFloat  = xx_height(30)
    
    static let col1Width: CGFloat      = xx_width(65)
    static let col2Width: CGFloat      = xx_width(80)
    
    static let col3Width: CGFloat      = (xx_screenWidth() - 2 * kConstraints.margin) - kConstraints.col1Width - kConstraints.col2Width - kConstraints.col4Width
    static let col4Width: CGFloat      = xx_width(70)
}


class BidInvestRecordSectionHeaderView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        makeUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func makeUI() {
        
        backgroundColor = Define.backgroundColor
        
//                let wrap = UIView(bgColor: xx_randomColor())
        let wrap = UIView()
        
        self.addSubview(wrap)
        wrap.snp_makeConstraints { (make) -> Void in
            
            make.edges.equalTo(kConstraints.wrapEdges)
        }
//        
//                let col1 = UIView(bgColor: xx_randomColor())
//                let col2 = UIView(bgColor: xx_randomColor())
//                let col3 = UIView(bgColor: xx_randomColor())
//                let col4 = UIView(bgColor: xx_randomColor())
        
                let col1 = UIView()
                let col2 = UIView()
                let col3 = UIView()
                let col4 = UIView()
        wrap.addSubview(col1)
        wrap.addSubview(col2)
        wrap.addSubview(col3)
        wrap.addSubview(col4)
        
        col1.snp_makeConstraints { (make) -> Void in
            
            make.top.left.bottom.equalTo(wrap)
            make.width.equalTo(kConstraints.col1Width)
        }
        col2.snp_makeConstraints { (make) -> Void in
            
            make.top.bottom.equalTo(wrap)
            make.left.equalTo(col1.snp_right)
            make.width.equalTo(kConstraints.col2Width)
        }
        col3.snp_makeConstraints { (make) -> Void in
            
            make.top.bottom.equalTo(wrap)
            make.left.equalTo(col2.snp_right)
            make.width.equalTo(kConstraints.col3Width)
        }
        col4.snp_makeConstraints { (make) -> Void in
            
            make.top.bottom.equalTo(wrap)
            make.left.equalTo(col3.snp_right)
            make.width.equalTo(kConstraints.col4Width)
        }
        
        
        let timeLabel = makeLabel("投资人")
        
        col1.addSubview(timeLabel)
        timeLabel.snp_makeConstraints { (make) -> Void in
            
            make.left.centerY.equalTo(col1)
        }
        
        let moneyLabel = makeLabel("投资金额")
        
        col2.addSubview(moneyLabel)
        moneyLabel.snp_makeConstraints { (make) -> Void in
            
            make.left.centerY.equalTo(col2)
            
        }
        
        let moneyUnitLabel = UILabel(title: "(元)", fontSize: 10)
        
        col2.addSubview(moneyUnitLabel)
        moneyUnitLabel.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(moneyLabel.snp_right).offset(1)
            make.centerY.equalTo(moneyLabel).offset(1)
            
        }
        let balanceLabel = makeLabel("申购时间 |")
        
        col3.addSubview(balanceLabel)
        balanceLabel.snp_makeConstraints { (make) -> Void in
            
            make.right.centerY.equalTo(col3)
            
        }
        
        let typeLabel =  makeLabel("投资状态")
        
        col4.addSubview(typeLabel)
        typeLabel.snp_makeConstraints { (make) -> Void in
            
            make.left.centerY.equalTo(col4)
            
        }
        
    }
    
    func makeLabel(text: String) -> UILabel {
        
        //        return UILabel(title: text, fontColor: Define.darkFontColor, bgColor: xx_randomColor(), fontSize: 12, maxWrapWidth: 0)
        return UILabel(title: text, fontColor: Define.darkFontColor, bgColor: nil, fontSize: 14, maxWrapWidth: 0)
    }
}
